<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  <title>购买</title>
  <link rel="stylesheet" type="text/css" href="./css/api.css" />
  <link rel="stylesheet" type="text/css" href="./css/aui.css" />
  <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
  <link rel="stylesheet" type="text/css" href="./css/style.css" />
  <script type="text/javascript" src="./script/api.js"></script>
  <script type="text/javascript" src="./script/aui-tab.js"></script>
  <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
  <script type="text/javascript" src="./script/aui-slide.js"></script>
  <script type="text/javascript" src="./script/base.js"></script>
  <script type="text/javascript" src="./script/doT.min.js"></script>
  <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
  <script type="text/javascript">
    function closeWin() {
      api.closeWin({});
    };
  </script>
</head>

<body>
  <!-- 头部 -->
  <header class="aui-bar aui-bar-nav pos">
    <a class="aui-pull-left aui-btn" onclick="closeWin()">
      <span class="aui-iconfont aui-icon-left"></span>
    </a>
    <div class="aui-title">购买</div>
  </header>
  <div class="header-d"></div>
  <style>
    body,
    html {
      min-height:calc(100% - 0);
    }
  </style>
  <div class="licai-buy">
    <dl>
      <dt>投资金额：</dt>
      <dd>
        <span id="money"></span>
      </dd>
    </dl>
    <dl>
      <dt>获利方式：</dt>
      <dd>
        <div class="aui-list-item-inner">
          <label><input class="aui-radio" type="radio" name="huolifangshi" checked value="1"> 每日获利</label>
        </div>
      </dd>
    </dl>
    <dl>
      <dt>预期收益：</dt>
      <dd id="shouyi"></dd>
    </dl>
    <dl>
      <dt>实付金额：</dt>
      <dd id="shifu"></dd>
    </dl>
    <div class="licai-buy-d">
      <div class="aui-clearfix"></div>
      <span onclick="xieyi1();">《借款协议》</span>
      <span onclick="xieyi2();">《委托授权书》</span>
      <span onclick="xieyi3();">《风险揭示书》</span>
      <span onclick="xieyi4();">《金可贷--电子签名数字证书用户申请确认函》</span>
    </div>
  </div>
  <div class="licai-buy-btn">
    <div class="aui-col-xs-6" onclick="buy();">购买</div>
    <div class="aui-col-xs-6" onclick="cal();">取消</div>
  </div>
</body>

<script type="text/javascript">


  apiready = function() {
    learn_info = api.pageParam.learn_info;
        // 投资金额
        learn_balance = learn_info.learn_balance;
        var rate_rate = learn_info.learn_info.rate;
        learn_id = learn_info.learn_info.id;

        $('#money').text('￥' + learn_balance);
        $('#shouyi').text('￥' + outputmoney(parseFloat(learn_balance) * parseFloat(parseFloat(rate_rate).toFixed(2)) / 100 / 365));
        $('#shifu').text('￥' + learn_balance);
      }

      function buy() {

        if (api.systemType == 'ios') {
          var password = $api.getStorage('password');
          if (password) {
            api.openWin({
              name: 'ios-unlockBuy',
              url: './ios-unlockBuy.html',
              bgColor:'#00744b',
              slidBackEnabled:false,
              pageParam:{
                login:'licai-buy-yuebao-2'
              },
            });
          } else {
            alert('请先添加手势密码');
          }

        } else {
          var isLock = $api.getStorage('isLock');
          if (isLock) {
            var screenLock = api.require('screenLock');
            screenLock.show({
              color: '#00744b'
            }, function(ret, err) {
              $api.setStorage('buy', true);
              if (ret.status == '111') {
                api.showProgress({
                  style: 'default',
                  animationType: 'fade',
                  title: '努力加载中...',
                  text: '先喝杯茶...',
                  modal: false
                });
                pay();
              }
            });
          } else {
            alert('请先添加手势密码');
          }
        }
      }



    //重新加载
    function reload() {
      alert(1); return;

      api.closeWin({
        name: 'ios-unlockBuy'
      });
      api.toast({
        msg: '解锁失败',
        duration: 2000,
        location: 'middle'
      });

      setTimeout("opeanReload()", 400);


    }

    function opeanReload() {
      api.openWin({
        name: 'ios-unlockBuy',
        url: './ios-unlockBuy.html',
        bgColor:'#00744b',
        slidBackEnabled:false,
        pageParam:{
          login:'licai-buy-yuebao-2'
        },
      });

    }

    function cal() {
      api.closeWin();
    }

    function pay(){

      var userid = $api.getStorage('userid');
      api.ajax({
       url: webAddress + '/index.php?ctl=uc_learn&act=do_invest',
       method: 'post',
       data: {
         values: {
           userid: userid,
           learn_id: learn_id,
           money: learn_balance,
         },
       }
     },function(ret, err){

       if (ret) {
         if (ret.status == '0') {

          alert(ret.info);
          return false;
        }else{

          api.toast({
            msg: '购买成功',
            duration: 2000,
            location: 'middle'
          });

          var gotoTiyanjin = 'updateData();';
          api.execScript({
            name: 'money',
            script: gotoTiyanjin,
          });

          api.closeToWin({
            name: 'money'
          });
        }
      } else {
        alert(err.msg);
      }
    });
    }

  </script>

  </html>
